<template>
  <div class="page-container">
    <!--工具栏-->
    <div class="toolbar" style="float:left;padding-top:10px;padding-left:15px;">
      <el-form :inline="true" :model="filters" :size="size">
        <el-row>
          <el-form-item>
            <el-input
              v-model="filters.number"
              placeholder="选择商家"
              style="width: 200px;"
              readonly
              @focus="showShop"
            ></el-input>
          </el-form-item>

          <el-form-item>
            <el-input
             readonly
              v-model="filters.number"
              placeholder="选择店铺名称"
              style="width: 200px;"
              @focus="showStore"
            ></el-input>
          </el-form-item>

          <el-form-item>
            <el-input
             readonly
              v-model="filters.equivalencyMin"
              placeholder="选择供应商"
              style="width: 200px;"
              @focus="showSupplier"
            ></el-input>
          </el-form-item>

          <el-form-item>
            <el-select v-model="filters.status" style="width: 200px;" placeholder="交易币别">
              <el-option label="CNY" value="0"></el-option>
              <el-option label="AUD" value="1"></el-option>
              <el-option label="USD" value="2"></el-option>
              <el-option label="GBP" value="3"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item>
            <el-date-picker
              v-model="filters.createMin"
              type="date"
              placeholder="生效日期始"
              format="yyyy 年 MM 月 dd 日"
              value-format="yyyy-MM-dd"
              style="width: 200px;"
            ></el-date-picker>
          </el-form-item>

          <el-form-item>
            <el-date-picker
              v-model="filters.createMax"
              type="date"
              placeholder="生效日期末"
              format="yyyy 年 MM 月 dd 日"
              value-format="yyyy-MM-dd"
              style="width: 200px;"
            ></el-date-picker>
          </el-form-item>

          <el-form-item>
            <el-date-picker
              v-model="filters.createMin"
              type="date"
              placeholder="失效日期始"
              format="yyyy 年 MM 月 dd 日"
              value-format="yyyy-MM-dd"
              style="width: 200px;"
            ></el-date-picker>
          </el-form-item>

          <el-form-item>
            <el-date-picker
              v-model="filters.createMax"
              type="date"
              placeholder="失效日期末"
              format="yyyy 年 MM 月 dd 日"
              value-format="yyyy-MM-dd"
              style="width: 200px;"
            ></el-date-picker>
          </el-form-item>

          <el-form-item>
            <el-input v-model="filters.numsMax" placeholder="商品名称" style="width: 200px;"></el-input>
          </el-form-item>

          <el-form-item>
            <el-input v-model="filters.numsMin" placeholder="商品编码" style="width: 200px;"></el-input>
          </el-form-item>

          <el-form-item>
            <el-input v-model="filters.fullMax" placeholder="商品条码" style="width: 200px;"></el-input>
          </el-form-item>

          <el-form-item>
            <el-input v-model="filters.fullMin" placeholder="合同编码" style="width: 200px;"></el-input>
          </el-form-item>

          <el-form-item>
            <el-select v-model="filters.status" style="width: 200px;" placeholder="合同类型">
              <el-option label="经销合同" value="0"></el-option>
              <el-option label="代销合同" value="1"></el-option>
            </el-select>
          </el-form-item>

          <el-row>
            

            <div style="float:right">
              <el-form-item>
                <kt-button
                  icon="fa fa-search"
                  :label="$t('action.search')"
                  type="primary"
                  @click="findPage(null)"
                />
              </el-form-item>
              <el-form-item>
                <kt-button
                  icon="fa fa-refresh" :label="$t('action.reset')"
                  type="primary"
                  @click="resetForm('filters')"
                />
              </el-form-item>

               <el-form-item>
              <kt-button label="导出" type="primary"  @click="exInfo" />
            </el-form-item>
            </div>
          </el-row>
        </el-row>
      </el-form>
    </div>
    <div class="toolbar" style="float:right;padding-top:10px;padding-right:15px;">
      <el-form :inline="true" :size="size">
        <el-form-item>
          <el-button-group>
            <el-tooltip content="刷新" placement="top">
              <el-button icon="fa fa-refresh" @click="findPage(null)"></el-button>
            </el-tooltip>
            <el-tooltip content="列显示" placement="top">
              <el-button icon="fa fa-filter" @click="displayFilterColumnsDialog"></el-button>
            </el-tooltip>
            <el-tooltip content="导出" placement="top">
              <el-button icon="fa fa-file-excel-o" @click="downloadExcel" id="downloadExcel"></el-button>
            </el-tooltip>
          </el-button-group>
        </el-form-item>
      </el-form>
      <!--表格显示列界面-->
      <table-column-filter-dialog
        ref="tableColumnFilterDialog"
        :columns="columns"
        @handleFilterColumns="handleFilterColumns"
      ></table-column-filter-dialog>
    </div>
    <!--表格内容栏-->
    <cy-table
      :height="350"
      ref="CyTable"
      :data="pageResult"
      :columns="filterColumns"
       :showOperation="false"
      @selectionChange="selectionChange"
      @findPage="findPage"
      @handleEdit="handleEdit"
      @handleDelete="handleDelete"
    ></cy-table>
    <!--新增编辑界面-->
    <el-dialog
      :title="operation?'新增':'编辑'"
      width="40%"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
    >
      <el-form
        :model="dataForm"
        label-width="80px"
        :rules="dataFormRules"
        ref="dataForm"
        :size="size"
        label-position="right"
      >
        <el-form-item label="所属商铺" prop="shop_id">
          <el-select v-model="dataForm.shop_id" placeholder="所属店铺" style="width: 100%;">
            <el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="等价金额" prop="money">
          <el-input type="number" v-model="dataForm.money" auto-complete="off" @input="watchMoney"></el-input>
        </el-form-item>
        <el-form-item label="需要达到的订单金额" prop="full_money">
          <el-input
            type="number"
            v-model="dataForm.full_money"
            auto-complete="off"
            @input="watchFullMoney"
          ></el-input>
        </el-form-item>
        <el-form-item label="需要达到的订单数量" prop="full_nums">
          <el-input
            type="number"
            v-model="dataForm.full_nums"
            auto-complete="off"
            @input="watchNums"
          ></el-input>
        </el-form-item>

        <el-form-item label="有效开始时间" prop="start">
          <el-date-picker
            v-model="dataForm.starttime"
            style="width:100%"
            type="date"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            placeholder="选择日期"
            v-on:input="watchStart"
          ></el-date-picker>
        </el-form-item>

        <el-form-item label="有效结束时间" prop="end">
          <el-date-picker
            v-model="dataForm.endtime"
            style="width:100%"
            type="date"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            placeholder="选择日期"
            v-on:input="watchEnd"
          ></el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :size="size" @click.native="dialogVisible = false">{{$t('action.cancel')}}</el-button>
        <el-button
          :size="size"
          type="primary"
          @click.native="submitForm"
          :loading="false"
        >{{$t('action.submit')}}</el-button>
      </div>
    </el-dialog>

    <el-dialog title="指定商品页面" :visible.sync="checkpages" width="30%" height="100%">
      <el-form style="text-align:center">
        <el-row>
          <el-form-item>
            <span>选择范围:</span>
            <el-input
              type="number"
              v-model="dataForm.money"
              auto-complete="off"
              @input="watchMoney"
            ></el-input>
          </el-form-item>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:right">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="checkpaged">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog
      title="选择商家"
      :visible.sync="showModel"
      width="45%"
      height="100%"
      :model="dataForm"
      label-width="80px"
      :rules="dataFormRules"
      ref="dataForm"
      :size="size"
      label-position="right"
    >
      <el-form
        style="text-align:left"
        :model="dataForm"
        label-width="80px"
        :rules="dataFormRules"
        ref="dataForm"
        :size="size"
        label-position="right"
      >
        <el-row>
          <div style="text-align:center">
            <el-form-item label="商家编码" prop="money" style="float:left;margin-left:90px">
              <el-input v-model="dataForm.money" auto-complete="off" width="20%"></el-input>
            </el-form-item>

            <el-form-item label="商家名称" prop="money" style="float:left;margin-left:90px">
              <el-input v-model="dataForm.money" auto-complete="off" width="20%"></el-input>
            </el-form-item>
          </div>
        </el-row>

        <div style="text-align:center">
          <el-form-item>
            <kt-button
              icon="fa fa-search"
              :label="$t('action.search')"
              type="primary"
              @click="findPage(null)"
            />
            <kt-button
              icon="fa fa-refresh" :label="$t('action.reset')"
              type="primary"
              @click="resetForm('filters')"
            />
          </el-form-item>
        </div>

        <el-table :data="tableData" border style="width: 100%" :visible.sync="showTable">
          <el-table-column prop="number" label="商家编码" width="280"></el-table-column>
          <el-table-column prop="name" label="商家名称" width="280"></el-table-column>
          <el-table-column prop="type" label="商家类型"></el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:right">
        <el-button @click="cancels">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 店铺table -->
    <el-dialog
      title="选择店铺"
      :visible.sync="showModel1"
      width="45%"
      height="100%"
      :model="dataForm"
      label-width="80px"
      :rules="dataFormRules"
      ref="dataForm"
      :size="size"
      label-position="right"
    >
      <el-form
        style="text-align:left"
        :model="dataForm"
        label-width="80px"
        :rules="dataFormRules"
        ref="dataForm"
        :size="size"
        label-position="right"
      >
        <el-row>
          <div style="text-align:center">
            <el-form-item label="店铺编码" prop="money" style="float:left;margin-left:90px">
              <el-input v-model="dataForm.money" auto-complete="off" width="20%"></el-input>
            </el-form-item>

            <el-form-item label="店铺名称" prop="money" style="float:left;margin-left:90px">
              <el-input v-model="dataForm.money" auto-complete="off" width="20%"></el-input>
            </el-form-item>
          </div>
        </el-row>

        <div style="text-align:center">
          <el-form-item>
            <kt-button
              icon="fa fa-search"
              :label="$t('action.search')"
              type="primary"
              @click="findPage(null)"
            />
            <kt-button
              icon="fa fa-refresh" :label="$t('action.reset')"
              type="primary"
              @click="resetForm('filters')"
            />
            
          </el-form-item>
        </div>

        <el-table :data="tableData1" border style="width: 100%" :visible.sync="showTable1">
          <el-table-column prop="checks" type="selection"></el-table-column>
          <el-table-column prop="name" label="商家名称" width="200"></el-table-column>
          <el-table-column prop="number" label="店铺编码" width="200"></el-table-column>
          <el-table-column prop="storename" label="店铺名称" width="200"></el-table-column>
          <el-table-column prop="storetype" label="店铺类型" width="200"></el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:right">
        <el-button @click="cancels2">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 供应商table -->
    <el-dialog
      title="选择供应商"
      :visible.sync="showModel2"
      width="45%"
      height="100%"
      :model="dataForm"
      label-width="80px"
      :rules="dataFormRules"
      ref="dataForm"
      :size="size"
      label-position="right"
    >
      <el-form
        style="text-align:left"
        :model="dataForm"
        label-width="80px"
        :rules="dataFormRules"
        ref="dataForm"
        :size="size"
        label-position="right"
      >
        <el-row>
          <div style="text-align:center">
            <el-form-item label="供应商编码" prop="money" style="float:left;margin-left:90px">
              <el-input v-model="dataForm.money" auto-complete="off" width="20%"></el-input>
            </el-form-item>

            <el-form-item label="供应商名称" prop="money" style="float:left;margin-left:90px">
              <el-input v-model="dataForm.money" auto-complete="off" width="20%"></el-input>
            </el-form-item>
          </div>
        </el-row>

        <div style="text-align:center">
          <el-form-item>
            <kt-button
              icon="fa fa-search"
              :label="$t('action.search')"
              type="primary"
              @click="findPage(null)"
            />
            <kt-button
              icon="fa fa-refresh" :label="$t('action.reset')"
              type="primary"
              @click="resetForm('filters')"
            />
          </el-form-item>
        </div>

        <el-table :data="tableData2" border style="width: 100%" :visible.sync="showTable2">
          <el-table-column prop="checks" type="selection"></el-table-column>
          <el-table-column prop="number" label="供应商编码" width="400"></el-table-column>
          <el-table-column prop="name" label="供应商名称" width="400"></el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:right">
        <el-button @click="cancels3">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import PopupTreeInput from "@/components/PopupTreeInput";
import CyTable from "@/views/Core/CyTable";
import KtButton from "@/views/Core/KtButton";
import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";
import { format } from "@/utils/datetime";
import { exportExcel } from "@/utils/excel";
export default {
  components: {
    PopupTreeInput,
    CyTable,
    KtButton,
    TableColumnFilterDialog
  },
  data() {
    return {
      //商家弹窗表格内容
      tableData: [
        {
          number: "300001",
          name: "王小虎",
          type: "张小二服饰"
        },
        {
          number: "300002",
          name: "录屏商家",
          type: "入驻商家"
        },
        {
          number: "300003",
          name: "测试商家",
          type: "自营商家"
        },
        {
          number: "300004",
          name: "育学园",
          type: "入驻商家"
        }
      ],
      //店铺弹窗表格内容
      tableData1: [
        {
          name: "张小二服饰",
          number: "jd_001",
          storename: "京东店",
          storetype: "线上店铺"
        },
        {
          name: "张小二服饰",
          number: "tm_001",
          storename: "张小二的二号店",
          storetype: "线上店铺"
        },
        {
          name: "张小二服饰",
          number: "jd_002",
          storename: "育学园天猫旗舰店",
          storetype: "线上店铺"
        },
        {
          name: "张小二服饰",
          number: "tm_002",
          storename: "张小二的bbc店铺",
          storetype: "线上店铺"
        }
      ],

      //供应商表格内容
      tableData2: [
        {
          number: "jd_001",
          name: "张小二服饰"
        },
        {
          number: "jd_002",
          name: "小杨服饰"
        },
        {
          number: "jd_003",
          name: "童颜无忌"
        },
        {
          number: "tm_004",
          name: "爱尚"
        }
      ],

      size: "small",
      filters: {
        code: "",
        shopname: "",
        storecode: "",
        storename: "",
        suppliercode: "",
        suppliername: "",
        procode: "",
        pronum: "",
        proname: "",
        pronorm: "",
        protype: "",
        calculateunit: "",
        stockunit: "",
        conversionrate: "",
        startnums: "",
        endarea: "",
        effectivedate: "",
        expirationdate: "",
        moneytype: "",
        purchaseprice: "",
        taxrate: "",
        unpurchaseprice: "",
        agreementprice: "",
        unagreementprice: "",
        transporttype: "",
        isfreight: "",
        supplier: "",
        contracttype: "",
        contractcode: "",
        contractttributes: "",
        remark: "",
        res: {
          total: 1,
          code: "0000",
          rows: [
            {
              code: "001",
              shopname: "张小二服饰",
              storecode: "003",
              storename: "育英",
              suppliercode: "1911290006866570",
              suppliername: "对账美元代销供应商	",
              procode: "1912050005104123",
              pronum: "23120500053263124",
              proname: "美元商品",
              pronorm: "颜色11:黄色	",
              protype: "安抚玩偶	",
              calculateunit: "件	",
              stockunit: "件	",
              conversionrate: "1.00",
              startnums: "0",
              endarea: "商家",
              effectivedate: "2019-11-28	",
              expirationdate: "2021-11-10	",
              moneytype: "USD",
              purchaseprice: "2.00",
              taxrate: "10.00%	",
              unpurchaseprice: "1.82	",
              agreementprice: "4.56",
              unagreementprice: "0.00	",
              transporttype: "公路	",
              isfreight: "不含运费	",
              supplier: "备用供应商	",
              contracttype: "代销合同	",
              contractcode: "HT1911290007105036",
              contractttributes: "自采合同	",
              remark: "无"
            }
          ]
        }
      },
      the_products: "",
      columns: [],
      filterColumns: [],
      pageRequest: { pageNum: 1, pageSize: 10 },
      pageResult: {},
      options: {},
      showModel: false,
      showTable: false,
      showModel1: false,
      showTable1: false,
      showModel2: false,
      showTable2: false,
      checkpages: false,
      operation: false, // true:新增, false:编辑
      dialogVisible: false, // 新增编辑界面是否显示
      editLoading: false,
      dataFormRules: {
        shop_id: [{ required: true, message: "请选择商铺", trigger: "blur" }],
       
        full_money: [
          { required: true, message: "请输入订单金额", trigger: "blur" }
        ],
        full_nums: [
          { required: true, message: "请输入订单数量", trigger: "blur" }
        ],
        starttime: [
          { required: true, message: "请输入有效开始时间", trigger: "blur" }
        ],
        endtime: [
          { required: true, message: "请输入有效结束时间", trigger: "blur" }
        ]
      },

      // 新增编辑界面数据
      dataForm: {
        shop_id: "",
        money: "",
        full_money: "",
        full_nums: "",
        starttime: "",
        endtime: " "
      },
      selections: []
    };
  },
  methods: {
    //商家table
    showShop() {
      this.showModel = true;
      this.showTable = true;
    },
    //店铺table
    showStore() {
      this.showModel1 = true;
      this.showTable1 = true;
    },
    showSupplier() {
      this.showModel2 = true;
      this.showTable2 = true;
    },
    //监听金额数量
    watchMoney() {
      let this_ = this;
      if (this_.dataForm.money < 0) {
        this.$message({ message: "等价金额不能为负 ", type: "error" });
        this_.dataForm.money = "";
      }
    },
    watchFullMoney() {
      let this_ = this;
      if (this_.dataForm.full_money < 0) {
        this.$message({ message: "订单金额不能为负", type: "error" });
        this_.dataForm.full_money = "";
        return;
      }
    },
    watchNums() {
      let this_ = this;
      if (this_.dataForm.full_nums < 0) {
        this.$message({ message: "订单数量不能为负", type: "error" });
        this_.dataForm.full_nums = "";
        return;
      }
    },
    //动态监听日期
    watchStart() {
      var this_ = this;
      let starttime = this_.dataForm.starttime;
      let endtime = this_.dataForm.endtime;
      if (new Date(starttime).getTime() >= new Date(endtime).getTime()) {
        this.$message({ message: "开始日期不能晚于结束日期 ", type: "error" });
        this_.dataForm.starttime = "";
        return false;
      }
    },

    watchEnd() {
      var this_ = this;
      let starttime = this_.dataForm.starttime;
      let endtime = this_.dataForm.endtime;
      if (new Date(endtime).getTime() <= new Date(starttime).getTime()) {
        this.$message({ message: "结束日期不能早于开始日期 ", type: "error" });
        this_.dataForm.endtime = "";
        return false;
      }
    },
    selectionChange: function(data) {
      this.selections = data.selections;
    },
    // 获取分页数据
    findPage: function(data) {
      
      this.$refs.CyTable.findPageStaticState(this.filters);
    },

    // 批量删除
    handleDelete: function(data) {
      var ids = "";
      for (var i = 0; i < data.params.length; i++) {
        ids = ids + data.params[i].id + ",";
      }
      data.params.t = "marketCoupons";
      data.params.ids = ids;
      this.utils.request.deleteUserInfo(data.params, data.callback);
    },

    // 显示新增界面
    handleAdd: function() {
      this.dialogVisible = true;
      this.operation = true;
      this.dataForm = {};
      console.log(dataForm);
    },
    //列表下载
    downloadExcel() {
      this.$confirm("确定下载列表文件?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let filename = "优惠卷配置";
          this.$refs.CyTable.exportData(
            this.filters,
            this.filterColumns,
            filename
          );
        })
        .catch(() => {});
    },
    // 显示编辑界面
    handleEdit: function(params) {
      console.log(params);
      this.dialogVisible = true;
      this.operation = false;
      this.dataForm = Object.assign({}, params.row);
    },

    // 编辑
    submitForm: function() {
      this.$refs.dataForm.validate(valid => {
        if (valid) {
          this.$confirm("确认提交吗？", "提示", {}).then(() => {
            this.editLoading = true;
            let params = Object.assign({}, this.dataForm);
            params.t = "marketCoupons";
            this.utils.request.saveMarketCoupon(params, this.saveSeckillBack);
          });
        }
      });
    },

    // 新增修改回调
    saveSeckillBack: function(data) {
      if (data.code == "0000") {
        this.$message({ message: "操作成功", type: "success" });
        this.dialogVisible = false;
        this.$refs["dataForm"].resetFields();
      } else {
        this.$message({ message: "操作失败, " + data.msg, type: "error" });
      }
      this.findPage({ t: "marketCoupons" });
      this.dialogVisible = false;
      this.operation = false;
      this.editLoading = false;
    },
    // 时间格式化
    dateFormat: function(row, column, cellValue, index) {
      return format(row[column.property]);
    },
    // 处理表格列过滤显示
    displayFilterColumnsDialog: function() {
      this.$refs.tableColumnFilterDialog.setDialogVisible(true);
    },
    // 处理表格列过滤显示
    handleFilterColumns: function(data) {
      this.filterColumns = data.filterColumns;
      this.$refs.tableColumnFilterDialog.setDialogVisible(false);
    },
    // 处理表格列过滤显示
    initColumns: function() {
      this.columns = [
        
        { prop: "code", label: "商家编码", minWidth: 50 },
        { prop: "shopname", label: "商家名称", minWidth: 100 },
        { prop: "storecode", label: "店铺编码", minWidth: 100 },
        { prop: "storename", label: "店铺名称", minWidth: 100 },
        { prop: "suppliercode", label: "供应商编码", minWidth: 50 },
        { prop: "suppliername", label: "供应商名称", minWidth: 100 },
        { prop: "procode", label: "商品编码", minWidth: 50 },
        { prop: "pronum", label: "商品条码", minWidth: 50 },
        { prop: "proname", label: "商品名称", minWidth: 100 },
        { prop: "pronorm", label: "商品规格", minWidth: 50 },
        { prop: "protype", label: "商品类目", minWidth: 50 },
        { prop: "calculateunit", label: "主计量单位", minWidth: 50 },
        { prop: "stockunit", label: "采购单位", minWidth: 50 },
        { prop: "conversionrate", label: "转换率", minWidth: 50 },
        { prop: "startnums", label: "起订量", minWidth: 50 },
        { prop: "endarea", label: "结算地", minWidth: 50 },
        { prop: "effectivedate", label: "生效日期", minWidth: 120 },
        { prop: "expirationdate", label: "失效日期", minWidth: 120 },
        { prop: "moneytype", label: "交易币别", minWidth: 50 },
        { prop: "purchaseprice", label: "含税采购价", minWidth: 50 },
        { prop: "taxrate", label: "进项税率", minWidth: 50 },
        { prop: "unpurchaseprice", label: "未税采购价", minWidth: 50 },
        { prop: "agreementprice", label: "含税协议价", minWidth: 50 },
        { prop: "unagreementprice", label: "未税协议价", minWidth: 50 },
        { prop: "transporttype", label: "运输方式", minWidth: 50 },
        { prop: "isfreight", label: "是否含运费", minWidth: 50 },
        { prop: "supplier", label: "主备供应商", minWidth: 100 },
        { prop: "contracttype", label: "合同类型", minWidth: 50 },
        { prop: "contractcode", label: "合同编码", minWidth: 100 },
        { prop: "contractttributes", label: "合同属性", minWidth: 50 },
        { prop: "remark", label: "备注", minWidth: 100 }
      ];
      var temp = [];
      $.each(this.columns, function(key, val) {
        temp.push(val);
      });
      this.filterColumns = temp;
    },
    resetForm(formName) {
      this.filters = {
        name: "",
        code: "",
        types: "",
        sortno: ""
      };
      this.findPage({ t: "marketCoupons" });
    },
    // 所属商品分类
    queryProType() {
      var that = this;
      this.utils.request.queryUserList({ t: "shop" }, function(data) {
        that.options = data.data;
      });
    },
    //启用停用按钮
    //启用
    startRule: function() {
      if (this.selections.length != 1) {
        this.$message({ message: "请选择一条数据", type: "error" });
        return;
      } else {
        var data = {};
        data.id = data.id = this.selections[0].id;
        data.t = "marketCoupons";
        data.status = 1;

        var this_ = this;
        this.utils.request.editUserInfo(data, function(res) {
          if (res.code == "0000") {
            this_.$message({ message: "启用成功", type: "success" });

            this_.findPage();
          } else {
            this_.$message({ message: res.msg, type: "error" });
          }
        });
      }
    },

    //停用按钮
    endRule: function() {
      if (this.selections.length != 1) {
        this.$message({ message: "请选择一条数据", type: "error" });
        return;
      } else {
        var data = {};
        data.id = this.selections[0].id;
        data.t = "marketCoupons";
        data.status = 0;

        var this_ = this;
        this.utils.request.editUserInfo(data, function(res) {
          if (res.code == "0000") {
            this_.$message({ message: "停用成功", type: "success" });

            this_.findPage();
          } else {
            this_.$message({ message: res.msg, type: "error" });
          }
        });
      }
    },
    //关联按钮
    relatedProducts: function() {
      if (this.selections.length != 1) {
        this.$message({ message: "请选择一条数据", type: "error" });
        this.checkpages = false;
        return;
      } else {
        this.checkpages = true;
      }
    },
    //指定商品
    checkpaged: function() {
      var data = {};
      data.id = this.selections[0].id;
      data.t = "marketCoupons";
      data.the_products = this.the_products;
      var this_ = this;
      if (" " != this.the_products && this.the_products == 2) {
        this.$router.push({
          path: "/product/productEntry",
          query: { couponid: this.selections[0].id }
        });
      } else {
        this.utils.request.editUserInfo(data, function(res) {
          if (res.code == "0000") {
            this_.$message({ message: "操作成功", type: "success" });
            this_.checkpages = false;
            this_.findPage();
          } else {
            this_.$message({ message: res.msg, type: "error" });
          }
        });
      }
    },
    //导出按钮
    exInfo:function(){
this.$message({ message: "导出成功", type: "success" });
    },
    //取消按钮
    cancels: function() {
      this.showModel = false;
      this.showTable = false;
    },
    cancels2: function() {
      this.showModel1 = false;
      this.showTable1 = false;
    },
    cancels3: function() {
      this.showModel2 = false;
      this.showTable2 = false;
    },
    cancel: function() {
      this.selections[0].id = " ";
      var this_ = this;
      this_.checkpages = false;
      this_.findPage();
    }
  },

  mounted() {
    this.initColumns();
    this.queryProType();
  }
};
</script>

<style scoped>
</style>